package com.fy.customview.bean;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 模拟数据设置内容
 */
public class SettingData {

    private int sonarCount;//声呐数量

    private float bankLength;//岸的长度,单位：m

    private float velocity0;//进入港口的初始速度，单位：m/s

    private float acceleration;//加速度，单位：m/s²

    private float angle;//船入港时船体与X轴的角度，取值大于-90，小于90

    private float shipLength;//船的长度

    private float distance0;//声呐探测到的第一个距离

    public float getDistance0() {
        return distance0;
    }

    public void setDistance0(float distance0) {
        this.distance0 = distance0;
    }

    public float getShipLength() {
        return shipLength;
    }

    public void setShipLength(float shipLength) {
        this.shipLength = shipLength;
    }

    public int getSonarCount() {
        return sonarCount;
    }

    public void setSonarCount(int sonarCount) {
        this.sonarCount = sonarCount;
    }

    public float getBankLength() {
        return bankLength;
    }

    public void setBankLength(float bankLength) {
        this.bankLength = bankLength;
    }

    public float getVelocity0() {
        return velocity0;
    }

    public void setVelocity0(float velocity0) {
        this.velocity0 = velocity0;
    }

    public float getAcceleration() {
        return acceleration;
    }

    public void setAcceleration(float acceleration) {
        this.acceleration = acceleration;
    }

    public float getAngle() {
        return angle;
    }

    public void setAngle(float angle) {
        this.angle = angle;
    }

    public String toJsonString(){
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("sonarCount",sonarCount);
            jsonObject.put("bankLength",bankLength);
            jsonObject.put("velocity0",velocity0);
            jsonObject.put("acceleration",acceleration);
            jsonObject.put("angle",angle);
            jsonObject.put("shipLength",shipLength);
            jsonObject.put("distance0",distance0);
            return jsonObject.toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static SettingData parseJson(String jsonStr){
        SettingData settingData = null;
        if (jsonStr != null){
            try {
                JSONObject jsonObject = new JSONObject(jsonStr);
                settingData = new SettingData();
                settingData.sonarCount = (int) jsonObject.opt("sonarCount");
                settingData.bankLength = (float) jsonObject.opt("bankLength");
                settingData.velocity0 = (float) jsonObject.opt("velocity0");
                settingData.acceleration = (float) jsonObject.opt("acceleration");
                settingData.angle = (float) jsonObject.opt("angle");
                settingData.shipLength = (float) jsonObject.opt("shipLength");
                settingData.distance0 = (float) jsonObject.opt("distance0");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return settingData;
    }

}
